package com.example.midicontrol.ui

import android.media.midi.MidiDeviceInfo
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.midicontrol.databinding.ActivityMainBinding
import com.example.midicontrol.midi.MidiDeviceManager
import com.example.midicontrol.midi.MidiUtils

class MainActivity : AppCompatActivity() {

    private lateinit var binding: ActivityMainBinding
    private lateinit var deviceManager: MidiDeviceManager

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        deviceManager = MidiDeviceManager(getSystemService(MidiManager::class.java))
        
        setupDeviceMonitoring()
        setupUIListeners()
    }

    private fun setupDeviceMonitoring() {
        deviceManager.registerDeviceCallback { isConnected, device ->
            val status = if (isConnected) "Connected" else "Disconnected"
            appendLog("${device.productName} $status")
        }
    }

    private fun setupUIListeners() {
        binding.btnScanDevices.setOnClickListener {
            scanMidiDevices()
        }
    }

    private fun scanMidiDevices() {
        // 扫描并显示可用设备
    }

    private fun appendLog(message: String) {
        binding.txtLog.append("$message\n")
    }
}
